# -*- encoding: utf-8 -*-
"""
@author: CarpeDiem
@data: 22/9/19
@version: 0.1
@description: 穷举法赢球票
@method: 不断开始计数进行比较
"""
N = int(input())
input_list = list(map(int, input().split()))
# print(input_list)
length = len(input_list)
count = 1
max_value = 1
for i in range(length):
    temp_list = input_list[i:] + input_list[:i]
    flag_list = [1 for _ in range(length)]
    for j in range(length):
        if temp_list[j] == j+1:
            flag_list[j] = 0
    
    
    for j in range(i, length):
        if input_list[i] > input_list[j]:
            count += 1
print(int(count *(count+1)/2))